//punchRecord.js
const app = getApp()
var i = 1
Page({
  data: {
    punchData:[],
    loadText:"加载更多",
    num:0,
  },
  
  onLoad: function () {
    var that = this

    /**
     * 请求打卡数据
     */
   wx.request({
     url: app.globalData.API_URL + "home/getPunchRecord",
     data: {
       token: app.globalData.token,
       page: i
     },
     header: {
       'content-type': 'application/x-www-form-urlencoded'
     },
     method: 'post',
     success: function (r) {
       if (r.data.code == 0) {
           that.setData({
             punchData:r.data.data
           })
       }
     }
   })
  },

  /**
   * 加载更多
   */
  loadMore: function () {
    var that = this
    i++;
    wx.request({
      url: app.globalData.API_URL + "home/getPunchRecord",
      data: {
        token: app.globalData.token,
        page: i
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'post',
      success: function (r) {
        if (r.data.code == 0) {
          if(r.data.data.length !==0){
            that.setData({
              punchData: that.data.punchData.concat(r.data.data)
            })
          }
          else {
            that.setData({
              num: 1
            })
          }
        }
      }
    })
  },
})